package com.zzyl.common.ai;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.chat.ChatResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AIModelInvoker {

    @Autowired
    private BaiduAIProperties baiduAIProperties;

    //设计提示词
 public  String qianfanInvoker(String prompt){
//设计提示词
     System.out.println(prompt);

    //创建千帆大模型
     Qianfan qianfan = new Qianfan(baiduAIProperties.getAccessKey(), baiduAIProperties.getSecretKey());

     System.out.println("21321321");
     //设计千帆大模型的数据
     ChatResponse response = qianfan.chatCompletion()
             //指定大模型的名称
             .model(baiduAIProperties.getQianfanModel())
             //添加用户输入的提示词
             .addMessage("user",prompt)
             //控制温度
             .temperature(0.7)
             //最大输出2000个token
             .maxOutputTokens(2000)
             //返回为json格式
             .responseFormat("json_object")
             .execute();
     //获取这个千帆大模型输出的结果
     String result =response.getResult();
     return result;


 }
}
